define(['../../../../js/lib/other/sweet-alert'],function() {
    return ['$scope','$location', '$interval','$timeout','bizProxy', function($scope,$location,$interval,$timeout,bizProxy) {
    	$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','loan'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','3-1'); 	//显示底部文字
    	
    	$scope.inviteCode = "";
    	if(!(resultData.loginUserData.userName != "" && resultData.loginUserData.userName != null)){
    		//未完善资料用户不可申请免息贷
			FIREFLY("请先去'我的'里面完善个人信息", "","",function(){
				$timeout(function(){
					history.back();
				},0);
			});
			return;
		}
    	
    	//点击去联系律师
    	$scope.contactLs = function(){
    		$scope.$emit("goNext","/searchLs");
    	}
    	
    	//点击去下一步
    	$scope.goNext = function(){
    		if($scope.inviteCode == ""){
    			$scope.$emit("promptAlertMsg","推荐码不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}
    		checkInviteCode();
    		
    	}
    	
    	//验证律师推荐码
    	function checkInviteCode(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.inviteCode = $scope.inviteCode;
        	
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("checkInviteCode",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$scope.$emit("loadingChange",false);
						$timeout(function(){
							//去下一步
							$scope.$emit("goNext","/fireLoanTable/"+$scope.inviteCode);
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							resultData.loginResultData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("loadingChange",false);
								$scope.$emit("promptAlertMsg",data.errorMsg);
				    			$scope.$emit("showCollect",true);
				    			$timeout(function(){
				    				$scope.$emit("showCollect",false);
				    				$scope.inviteCode = "";
				    			},transData.promptTime);
							}
		    			}else{
			    			$scope.$emit("loadingChange",false);
							$scope.$emit("promptAlertMsg","连接超时");
			    			$scope.$emit("showCollect",true);
			    			$timeout(function(){
			    				$scope.$emit("showCollect",false);
			    			},transData.promptTime);
		    			}
		    		});
    	}
    	
        $scope.$apply();
    }];
});